package qianfeng.com.meijiadaka.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.List;

import qianfeng.com.meijiadaka.R;
import qianfeng.com.meijiadaka.bean.OneDayBean;

/**
 * Created by yanshihao on 2017/2/10.
 */

public class OneDayAdapter extends RecyclerView.Adapter<OneDayAdapter.ViewHolder> {

    private Context mContext;
    private List<OneDayBean.ResultBean> mList;
    private RecyclerView mRecyclerView;

    public OneDayAdapter(Context context, List<OneDayBean.ResultBean> list) {
        mContext = context;
        mList = list;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.oneday, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = mRecyclerView.getChildAdapterPosition(v);
                Toast.makeText(mContext,"点击"+position,Toast.LENGTH_SHORT).show();
            }
        });
        return viewHolder;
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        mRecyclerView=recyclerView;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv.setText(mList.get(position).getTitle());
        Glide.with(mContext).load(mList.get(position).getThumbUrl()).into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv;
        TextView tv;

        public ViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.oneday_iv);
            tv = (TextView) itemView.findViewById(R.id.oneday_tv);
        }
    }
}